<?php
namespace process;

class Monitor
{
    protected $paths = [];
    protected $lastMtimes = [];

    public function __construct(array $paths = [])
    {
        $this->paths = $paths;
        $this->checkAllFilesChange();
    }

    public function checkAllFilesChange()
    {
        $changed = false;
        foreach ($this->paths as $path) {
            if ($this->checkFileChange($path)) {
                $changed = true;
            }
        }
        return $changed;
    }

    protected function checkFileChange($path)
    {
        if (!is_file($path)) {
            return false;
        }
        $mtime = filemtime($path);
        if (!isset($this->lastMtimes[$path])) {
            $this->lastMtimes[$path] = $mtime;
            return false;
        }
        if ($this->lastMtimes[$path] !== $mtime) {
            $this->lastMtimes[$path] = $mtime;
            return true;
        }
        return false;
    }
} 